package com.oracle.rentcar.test;

import com.oracle.rentcar.RentcarApplication;
import com.oracle.rentcar.mapper.CustomerMapper;
import com.oracle.rentcar.pojo.Customer;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RunWith(SpringRunner.class)
// 底层用junit SpringJUnit4ClassRunner
@SpringBootTest(classes= {RentcarApplication.class}) //RentcarApplication是SpringBoot的主类
public class CustomerTest2 {

    @Autowired
    private CustomerMapper customerMapper;

    // 注意org.junit.Test，不能是org.junit.jupiter.api.Test;
    @Test
    public void testSelectCustomer(){
        List<Customer> customers = customerMapper.selectCustomer();
        for(Customer customer:customers){
            System.out.println(customer);
        }
    }

    @Test
    public void testDeleteCustomer(){
        int n = customerMapper.deleteCustomer(43);
        System.out.println(n);
    }

    @Test
    public void bathDeleteCustomerByIds(){
        List<Integer> list = new ArrayList<Integer>();
        list.add(35);
        list.add(32);
        list.add(33);

        int n = customerMapper.bathDeleteCustomer(list);
        System.out.println("n: " + n);
    }

    @Test
    public void testSelectCustomerById(){
        Customer customer = customerMapper.findCustomer(22);
        System.out.println(customer);
    }


    @Test
    public void testAddCustomer(){
        Customer customer = new Customer();
        customer.setCusName("黄花");
        customer.setPassword("10000");

        int n = customerMapper.addCustomer(customer);
        System.out.println(n);
    }




    @Test
    public void testCheckCustomerName(){
        Customer customer = customerMapper.checkCustomerName("李华");

        if (customer != null){
            System.out.println("存在这个名字的会员");
        }else {
            System.out.println("会员不存在");
        }
    }

    @Test
    public void testSelectCustomerByParams(){
        List<Map<String, Object>> maps = customerMapper.selectCustomerByParams("s", "");

        for (Map<String, Object> map: maps) {
            System.out.println(map);
        }
    }

    @Test
    public void testCustomerLogin(){
        Customer customer = customerMapper.customerLogin("李文慧", "123456");
        System.out.println(customer.getCusName() + "登陆成功");
    }


}



